package com.cssw.fyzb.busi.api.live;

import com.cssw.fyzb.busi.service.live.GiftService;
import com.cssw.fyzb.core.model.dodb.GiftLog;
import com.cssw.fyzb.core.model.vo.live.GiftLogVo;
import com.cssw.fyzb.core.util.DateUtil;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import com.ydn.dbframe.plugin.activerecord.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 用户赠送礼物列表
 *
 * @author wondream
 */
@Function(description = "用户赠送礼物列表", parameters = {
        @Parameter(name = "userId", type = Type.String, description = "用户标识", required = true),
        @Parameter(name = "pageNumber", type = Type.String, description = "当前页，从1开始", required = true),
        @Parameter(name = "pageSize", type = Type.String, description = "页大小", required = true)
})
@Component
public class ListGiftLog implements Action {

    @Autowired
    GiftService giftService;

    @Override
    public Response execute(Request request) throws Exception {
        Long userId = request.getLong("userId");
        Integer pageNumber = request.getInteger("pageNumber");
        Integer pageSize = request.getInteger("pageSize");
        Page<GiftLog> page = giftService.listGiftLog(userId, pageNumber, pageSize);
        List<GiftLogVo> list = new ArrayList<>();
        GiftLogVo giftLogVo = null;
        for (GiftLog p : page.getList()) {
            giftLogVo = new GiftLogVo();
            giftLogVo.setCreateTime(DateUtil.format(p.getCreateTime()));
            giftLogVo.setGiftId(p.getGiftId());
            giftLogVo.setNums(p.getNums());
            giftLogVo.setTradeId(p.getTradeId());
            giftLogVo.setTradeName(p.getTradeName());
            giftLogVo.setTradeType(p.getTradeType());
            giftLogVo.setType(p.getType());
            list.add(giftLogVo);
        }
        return Response.success().put("list", list).put("total", page.getTotalPage()).put("count", page.getTotalRow());
    }
}

